#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
class Solution {
public:
    int longestArithSeqLength(vector<int>& nums) {
        int n = nums.size();
        vector<vector<int>>dp(n, vector<int>(n, 2));
        unordered_map<int, int> hash;
        int ret = 2;
        for (int i = 0; i < n; i++)
            hash[nums[i]] = i;
        for (int i = 1; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                int a = 2 * nums[i] - nums[j];
                if (hash.count(a))
                {
                    dp[i][j] = dp[hash[a]][i] + 1;
                }
                ret = max(ret, dp[i][j]);
            }
        }
        return ret;
    }
};

int main()
{
    vector<int> nums = {24, 13, 1, 100, 0, 94, 3, 0, 3};
    Solution().longestArithSeqLength(nums);
    return 0;
}